<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>备件列表</title>
		<!-- css代码 start -->
		<link href="../../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../../css/global.css" rel="stylesheet" />
		<link href="../../../../css/style.css" rel="stylesheet" />
		<style>
			#div {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 70%;
				left: 50%;
			}
			.item_box .item .text span{
				width: auto;
				display: inherit;
				float: right;
				height: auto;
				flex: 1;
			}
			.item_box .item .text{
				display: flex;
				min-height: 30px;
				height: auto;
			}
			.item_box .item .text .info-label{
				width: 90px;
			}
			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover .mui-popover-arrow:after {
				width: 0px;
			}
			.item_box .item .text{
				height: auto;
				line-height: 24px;
				overflow: hidden;
			}
			.popover .my-content-cell {
				padding: 0;
				margin: 0 10px;
			}
			.popover .arrow-right-position {
				right: -5px;
			}

		</style>
		<!-- css代码 end -->
	</head>
	<body>
		<div id="div"></div>
		<div id="popover" class="mui-popover shadow popover">
			<p class="title" id="title">您确定要删除该备件信息吗？</p >
			<div class="btn_box" style="overflow: hidden" >
				<span class="fl" onclick="closePopover()">取消</span>
				<span class="fr red" onclick="fixedDel()">确定</span>
			</div>
		</div>
		<!-- html代码 start -->
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">备件列表</h1>
		</header>
		<div class="mui-content">
			<div class="item_box" id="liebiao">
				<!-- <div class="item">
					<p class="bar"><span class="number">1170001</p>
					<div class="text">2132345465768<span>借货单号</span></div>
					<div class="text">备件1<span>备件名称</span></div>
					<div class="text">2345123456<span>备件序列号</span></div>
					<div class="attribute autoHeight">
						<p>数量：<span>11</span></p>
						<p>单价：<span>11</span></p>
						<p>总价：<span>11</span></p>
					</div>
				</div>
				<div class="item" >
					<p class="bar"><span class="number">1170001</p>
					<div class="text">2132345465768<span>借货单号</span></div>
					<div class="text">备件1<span>备件名称</span></div>
					<div class="text">2345123456<span>备件序列号</span></div>
					<div class="attribute autoHeight">
						<p>数量：<span>11</span></p>
						<p>单价：<span>11</span></p>
						<p>总价：<span>11</span></p>
					</div>
				</div> -->
			</div>
		</div>
		<!-- html代码 end -->

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/utils/h.js"></script>
		<script src="../../../../js/constant.js"></script>
		<script src="../../../../js/common.js"></script>
		<script src="../../../../js/utils/base64.js"></script>
		<script src="../../../../js/utils/md5.js"></script>
		<script src="../../../../js/utils/sortMap.js"></script>
		<script src="../../../../js/utils/http.js"></script>
		<script src="../../../../js/app.js"></script>
		<!-- 基础js end -->

		<script type="text/javascript" charset="utf-8">
			var serviceNo;
			var ServiceNoticeId;
			var needDelPartId; // 需要删除的备件信息id
			var submitStatus;
			var delPartIds;
			var reportId;
			(function($, doc) {
				$.init();

				$.plusReady(function() {

					var self = plus.webview.currentWebview();
					// 获取上一个页面传过来的参数并显示到页面
					reportId = self.reportId ? self.reportId : "idNull";
					serviceNo = self.serviceNo;
					ServiceNoticeId = self.ServiceNoticeId;
					helpId = self.helpId;
					submitStatus = self.submitStatus;
					delPartIds = '';
					initData();

				});
			}(mui, document));

			// 数据初始方法
			function initData(){
				// 旧接口 cc/installation/quality/report/selectReportPort 20200611 修复删除安装质量报告备件被替换为下面的接口
				app.showWaiting();
				ajaxGet(BASE_URL + "cc/installation/quality/report/selectReportPortByInstallation", {
					"reportId": reportId,
					"serviceNo": serviceNo,
					"helpId":helpId,
					"type":5
				}, function(data) {
					app.closeWaiting();
					h("#liebiao").html("");
					if(data.code==200){
						var html = "";
						if(data.data && data.data.length > 0){
							for(var i=0;i<data.data.length;i++){
								var das = data.data[i];
								var partNumber = das.partNumber==undefined?"无":das.partNumber;
								var loanNumber = das.loanNumber==undefined?"无":das.loanNumber;
								var partName = das.partName==undefined?"无":das.partName;
								var partSerialNumber = das.partSerialNumber==undefined?"无":das.partSerialNumber;
								var qtyCount = das.qtyCount==undefined?"无":das.qtyCount;
								var price = das.partName==undefined?"无":das.price;
								var totalprice = das.totalprice==undefined?"无":das.totalprice;
								var partName = das.partName==undefined?"无":das.partName;
								html += '<div class="item" >'
									html += '<p class="bar"><span class="number"><img src="../../../../images/icon_204.png" />'+partNumber+'</span>' +
											'<span class="del" onclick="delPart('+das.id+')">删除</span>' +
											'</p>'
									// html += '<div class="text"><div class="info-label">借货单号：</div><span>'+loanNumber+'</span></div>'
									html += '<div class="text"><div class="info-label">备件名称：</div><span>'+partName+'</span></div>'
									html += '<div class="text"><div class="info-label">备件数量：</div><span>'+qtyCount+'</span></div>'
									// html += '<div class="text"><div class="info-label">备件序列号：</div><span>'+partSerialNumber+'</span></div>'
									/*html += '<div class="attribute autoHeight">'
										html += '<p>数量：<span>'+qtyCount+'</span></p>'
										html += '<p>单价：<span>'+price+'</span></p>'
										html += '<p>总价：<span>'+totalprice+'</span></p>'
									html += '</div>'*/
								html += '</div>';
							}
							h("#liebiao").html(html);
							if (submitStatus && submitStatus == '1') {
								h('.del').hide()
							}
						}else{
							var html = '<div class="nodata">—— 暂无数据 ——</div>';
							h("#liebiao").html(html);
						}
					} else {
						var html = '<div class="nodata">—— 暂无数据 ——</div>';
						h("#liebiao").html(html);
						app.toast(data.msg);
					}
				}, function(errorMsg) {
					app.closeWaiting();
					var html = '<div class="nodata">—— 暂无数据 ——</div>';
					h("#liebiao").html(html);
					app.toast("数据获取失败，请检查网络连接");
				});
			}
			// 删除备件后查询列表 方法
			function delPartData(){
				ajaxGet(BASE_URL + "cc/installation/quality/report/selectReportPortByDel", {
					"serviceNo": serviceNo,
					"helpId":helpId,
					"type":5
				}, function(data) {
					app.closeWaiting();
					h("#liebiao").html("");
					if(data.code==200){
						var html = "";
						if(data.data && data.data.length > 0){
							for(var i=0;i<data.data.length;i++){
								var das = data.data[i];
								var partNumber = das.partNumber==undefined?"无":das.partNumber;
								var loanNumber = das.loanNumber==undefined?"无":das.loanNumber;
								var partName = das.partName==undefined?"无":das.partName;
								var partSerialNumber = das.partSerialNumber==undefined?"无":das.partSerialNumber;
								var qtyCount = das.qtyCount==undefined?"无":das.qtyCount;
								var price = das.partName==undefined?"无":das.price;
								var totalprice = das.totalprice==undefined?"无":das.totalprice;
								var partName = das.partName==undefined?"无":das.partName;
								html += '<div class="item" >'
									html += '<p class="bar"><span class="number"><img src="../../../../images/icon_204.png" />'+partNumber+'</span>' +
											'<span class="del" onclick="delPart('+das.id+')">删除</span>' +
											'</p>'
									// html += '<div class="text"><div class="info-label">借货单号：</div><span>'+loanNumber+'</span></div>'
									html += '<div class="text"><div class="info-label">备件名称：</div><span>'+partName+'</span></div>'
									html += '<div class="text"><div class="info-label">备件数量：</div><span>'+qtyCount+'</span></div>'
									// html += '<div class="text"><div class="info-label">备件序列号：</div><span>'+partSerialNumber+'</span></div>'
									/*html += '<div class="attribute autoHeight">'
										html += '<p>数量：<span>'+qtyCount+'</span></p>'
										html += '<p>单价：<span>'+price+'</span></p>'
										html += '<p>总价：<span>'+totalprice+'</span></p>'
									html += '</div>'*/
								html += '</div>';
							}
							h("#liebiao").html(html);
							if (submitStatus && submitStatus == '1') {
								h('.del').hide()
							}
						}else{
							var html = '<div class="nodata">—— 暂无数据 ——</div>';
							h("#liebiao").html(html);
						}
					} else {
						var html = '<div class="nodata">—— 暂无数据 ——</div>';
						h("#liebiao").html(html);
						app.toast(data.msg);
					}
				}, function(errorMsg) {
					app.closeWaiting()
					var html = '<div class="nodata">—— 暂无数据 ——</div>';
					h("#liebiao").html(html);
					app.toast("数据获取失败，请检查网络连接");
				});
			}
			function fixedDel() {
				mui("#popover").popover('toggle', document.getElementById("div"));
				app.showWaiting('删除中...')
				// 旧接口 cc/report/port/removeReportPort 20200611 修复删除安装质量报告备件被替换为下面的接口
				ajaxGet(BASE_URL + 'cc/report/port/removeReportPortByInstallation', {
					id: needDelPartId
				}, function(data) {
					if (data.code === 200) {
						console.log("0===");
						console.log(delPartIds);
						app.toast('删除成功');
						delPartIds+=needDelPartId+',';
						console.log("1===");
						console.log(delPartIds);
						var saveList = plus.webview.getWebviewById('view/service/report/installationquality/add.html');
						saveList.evalJS('childDelPartIds("'+delPartIds+'")');
						delPartData();
					} else {
						app.closeWaiting()
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					app.toast(errorMsg)
				})
			}

			function closePopover() {
				mui("#popover").popover('toggle', document.getElementById("div"));
			}

			function delPart(id) {
				needDelPartId = id;
				mui("#popover").popover('toggle', document.getElementById("div"));
			}
		</script>
		<!-- js代码 end -->
	</body>
</html>
